package javaapplication1.view;

import java.util.List;
import java.util.Scanner;

import javaapplication1.control.SellPetControl;
import javaapplication1.model.Pet;
import javaapplication1.model.PetOwner;
import javaapplication1.model.PetStore;
import javaapplication1.dao.PetDao;
import javaapplication1.dao.PetOwnerDao;
import javaapplication1.dao.PetStoreDao;
import javaapplication1.dao.oracleImpl.PetDaoOracleImpl;
import javaapplication1.dao.oracleImpl.PetOwnerDaoOracleImpl;
import javaapplication1.dao.oracleImpl.PetStoreDaoOracleImpl;

public class SellPetView {

	private static PetDao petDao = new PetDaoOracleImpl();
	private static PetOwnerDao petOwnerDao = new PetOwnerDaoOracleImpl();
	private static PetStoreDao petStoreDao = new PetStoreDaoOracleImpl();
	private static SellPetControl sellPetControl = new SellPetControl();

	public static void sellPetView() {
		List<Pet> petList = petDao.retrievePetByOwnerId(SessionScope.getId());
		System.out.println("******************************");
		System.out.println("宠物列表");
		for (int i = 0; i < petList.size(); i++) {
			System.out.print("序号：" + (i + 1));
			System.out.print("\t");
			System.out.print("名字：" + petList.get(i).getName());
			System.out.print("\t");
			System.out.print("品种：" + petList.get(i).getTypeName());
			System.out.print("\t");
			System.out.print("价格：" + petList.get(i).getPrice());
			System.out.println();
		}
		System.out.println("******************************");
		Scanner scanner = new Scanner(System.in);
		System.out.print("你的选择：");
		int choose = scanner.nextInt();
		if (choose > 0 && choose < petList.size() + 1) {
			if (SessionScope.getRole() == 1) {
				List<PetStore> petStoreList = petStoreDao.retrievePetStoreAll();
				System.out.println("******************************");
				System.out.println("宠物商店列表");
				for (int i = 0; i < petStoreList.size(); i++) {
					System.out.println("第" + (i + 1) + "个宠物商店，名字叫："
							+ petStoreList.get(i).getName());
				}
				System.out.println("******************************");
				System.out.print("你的选择：");
				int chooseStore = scanner.nextInt();
				if (chooseStore > 0 && chooseStore < petStoreList.size() + 1) {
					sellPetControl.sellPetControl(petList.get(choose - 1),
							petStoreList.get(chooseStore - 1).getId());
				} else {
					System.out.println("输入有误，请重新输入");
					SellPetView.sellPetView();
				}
			} else if (SessionScope.getRole() == 2) {
				List<PetOwner> petOwnerList = petOwnerDao.retrievePetOwnerAll();
				System.out.println("******************************");
				System.out.println("宠物主人列表");
				for (int i = 0; i < petOwnerList.size(); i++) {
					System.out.println("第" + (i + 1) + "个宠物主人，名字叫："
							+ petOwnerList.get(i).getName());
				}
				System.out.println("******************************");
				System.out.print("你的选择：");
				int chooseOwner = scanner.nextInt();
				if (chooseOwner > 0 && chooseOwner < petOwnerList.size() + 1) {
					sellPetControl.sellPetControl(petList.get(choose - 1),
							petOwnerList.get(chooseOwner - 1).getId());
				} else {
					System.out.println("输入有误，请重新输入");
					SellPetView.sellPetView();
				}
			}
		} else {
			System.out.println("输入有误，请重新输入");
			SellPetView.sellPetView();
		}
	}

}